/*
 * @Author: kanglang
 * @Date: 2020-12-02 15:52:08
 * @LastEditors: 汪滔
 * @LastEditTime: 2021-07-20 16:00:47
 * @Description: 协议组件
 */
import React, { Component } from 'react';
import { StyleSheet, View, Text } from 'react-native';
import XmWebview from 'react-native-autoheight-webview';
import { ScrollView } from 'react-native-gesture-handler';

import { _ } from '@/common';
import { px2dp, screenWidth } from '@/styles';

export default class Agreement extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    const { xmData } = this.props;
    return (
      <View style={styles.container}>
        {
          xmData && JSON.stringify(xmData) !== '{}' ?
            <ScrollView showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false}>
              <XmWebview
                style={{ width: '94%', marginLeft: '3%', marginTop: px2dp(10) }}
                enableBaseUrl
                source={this.newHtml()}
                scrollEnabled={false}
                showsVerticalScrollIndicator={false}
                showsHorizontalScrollIndicator={false}
              />
            </ScrollView>
            :
            <View style={styles.noText}>
              <Text style={styles.TextSize}>{this.props.noTip}</Text>
            </View>
        }
      </View>
    );
  }

  newHtml() {
    const { contentType, contentInfo, contentUrl } = this.props.xmData;
    if (contentType === 2) {
      return {
        html: _.customStyle + contentInfo
      };
    }
    return { uri: contentUrl };
  }
}
const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    height: '100%',
  },
  center: {
    textAlign: 'center'
  },
  mt20: {
    marginTop: px2dp(20)
  },
  f18: {
    fontSize: px2dp(32)
  },
  f14: {
    fontSize: px2dp(28)
  },
  bBlack: {
    color: '#333232'
  },
  noText: {
    width: screenWidth,
    flex: 1,
    justifyContent: 'center',
    alignItems: 'center'
  },
  TextSize: {
    fontSize: px2dp(36)
  },
  backImg: {
    width: 24,
    height: 24,
    marginLeft: 12,
  },
});
